﻿Public Class xtf_ABMptioga

    Dim ulg_row As DataRow
    Dim obj_ptioga_ As cls_ptioga_ = Nothing

    Public Sub New()
        InitializeComponent()
        'Cargarsiglafiscal_()
        AgregarValidaciones()
    End Sub

    Public Shadows Sub Nuevo(ByRef listado As Form)
        Try
            frm_listado = listado
            Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - Nuevo"
            obj_ptioga_ = New cls_ptioga_
            btn_Registro.Enabled = False
            Me.Show()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Shadows Sub Modificar(ByRef ptioga As cls_ptioga_, ByRef listado As Form, ByRef row As DataRow)
        If IsNothing(obj_ptioga_) Then
            obj_ptioga_ = New cls_ptioga_
        End If
        obj_ptioga_ = ptioga
        frm_listado = listado
        ulg_row = row : bbi_imprimir.Enabled = True

        Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - " & obj_ptioga_.ToString
        txt_ID.Text = obj_ptioga_.idptioga
        txt_diametronominalp.Text = obj_ptioga_.diametronominalp
        txt_diametronominalm.Text = obj_ptioga_.diametronominalm
        txt_odp.Text = obj_ptioga_.odp
        txt_odm.Text = obj_ptioga_.odm
        txt_ansi.Text = obj_ptioga_.ansi
        txt_asme.Text = obj_ptioga_.asme
        txt_asmes.Text = obj_ptioga_.asmes
        txt_espesorp.Text = obj_ptioga_.espesorp
        txt_espesorm.Text = obj_ptioga_.espesorm
        txt_pesol.Text = obj_ptioga_.pesol
        txt_pesok.Text = obj_ptioga_.pesok

        btn_Registro.Enabled = True

        Me.Show()

    End Sub

    Public Overrides Function ComprobarDatos() As Boolean
        If Not ControlarValidaciones() Then
            ErrManagerShow("000004", Me)
            Return False
        End If
        Return True
    End Function

    Public Shadows Sub btn_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Guardar.Click
        If ComprobarDatos() Then
            obj_ptioga_.diametronominalp = txt_diametronominalp.Text
            obj_ptioga_.diametronominalm = txt_diametronominalm.Text
            obj_ptioga_.odp = txt_odp.Text
            obj_ptioga_.odm = txt_odm.Text
            obj_ptioga_.ansi = txt_ansi.Text
            obj_ptioga_.asme = txt_asme.Text
            obj_ptioga_.asmes = txt_asmes.Text
            obj_ptioga_.espesorp = txt_espesorp.Text
            obj_ptioga_.espesorm = txt_espesorm.Text
            obj_ptioga_.pesol = txt_pesol.Text
            obj_ptioga_.pesok = txt_pesok.Text

            If txt_ID.Text = "" Then
                obj_ptioga_.Nuevo(True)
                If frm_listado.Visible Then
                    ulg_row = CType(frm_listado, xtf_LISTADOptioga_).AgregarItem(obj_ptioga_)
                End If
                Modificar(obj_ptioga_, frm_listado, ulg_row)
            Else
                obj_ptioga_.Modificar()
                If frm_listado.Visible Then
                    CType(frm_listado, xtf_LISTADOptioga_).ModificarItem(obj_ptioga_, ulg_row)
                End If
                Modificar(obj_ptioga_, frm_listado, ulg_row)
            End If
            flg_Modificado = False : btn_Guardar.Enabled = False : bbi_guardar.Enabled = False
        End If
    End Sub

    Private Sub btn_Registro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Registro.Click
        If Not IsNothing(obj_ptioga_.registro) Then
            Dim ABMRegistro As New xtf_ABMRegistro(obj_ptioga_.registro)
            If ABMRegistro.ShowDialog() = Windows.Forms.DialogResult.OK Then
                flg_Modificado = True
            End If
        End If
    End Sub


    Private Sub btn_Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cerrar.Click
        If flg_Modificado Then
            bol_comprobarCerrado = False
            Select Case ErrManagerShow("000001", Me)
                Case Windows.Forms.DialogResult.Yes
                    If ComprobarDatos() Then
                        btn_Guardar_Click(Nothing, Nothing)
                    Else
                        Exit Sub
                    End If
                Case Windows.Forms.DialogResult.Cancel : bol_comprobarCerrado = True
                    Exit Sub
            End Select
        End If
        Me.Dispose()
    End Sub
End Class